import json

import os

from common import is_guid_file

valid_file_path_list = list()


def read_valid_files(folder_path, file_extension):
    # 检查文件夹是否存在
    if not os.path.exists(folder_path):
        print(f"文件夹路径 {folder_path} 不存在！")
        return

    # 遍历文件夹中的所有文件
    for file_name in os.listdir(folder_path):
        # 检查文件后缀是否为.json
        if file_name.endswith(file_extension) and is_guid_file(file_name):
            file_path = os.path.join(folder_path, file_name)
            valid_file_path_list.append(file_path)
            # try:
            #     # 打开并读取文件内容
            #     with open(file_path, "r", encoding="utf-8") as file:
            #         print(f"processing {file_name}")
            #         json_content = json.load(file)
            #         callback(os.path.join(folder_path, file_name), json_content)
            # except json.JSONDecodeError as e:
            #     print(f"解析文件 {file_name} 时出错：{e}")
            # except Exception as e:
            #     print(f"读取文件 {file_name} 时出错：{e}")
    return valid_file_path_list
